import '../lib/sockjs.min.js';// websocket兼容支持包

function webSocket({wsUrl, onOpen, onError, onClose, onMessage}) {
	let websocket;
	if ('WebSocket' in window) {
		websocket = new WebSocket(wsUrl);
	} else if ('MozWebSocket' in window) {
		websocket = new MozWebSocket(wsUrl);
	} else {
		websocket = new SockJS(wsUrl.replace('websocket', 'sockjs'));
	}
	if(websocket) {
		websocket.onopen = onOpen || function() {};
		websocket.onerror = onError || function() {};
		websocket.onclose = onClose || function() {};
		websocket.onmessage = onMessage || function() {};
	}
	return websocket;
}

export {
	webSocket
}
